package com.group12.liuxinpeng.organ.controller;

import com.group12.liuxinpeng.common.control.BaseController;
import com.group12.liuxinpeng.mybatis.ztree.ZtreeEntity;
import com.group12.liuxinpeng.organ.service.OrganService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("/organinfo")
public class OrganController extends BaseController {

    private Logger logger = LogManager.getLogger(this.getClass().getName());
    @Resource
    private OrganService organService;

    @Resource
    private MessageSource messageSource;

    @RequestMapping("/page")
    public String rolePage(){
        return "organinfo/page";
    }

    @RequestMapping("/getOrganZtreeListByOrganId")
    @ResponseBody
    public List<ZtreeEntity> getOrganZtreeListByOrganId(@RequestParam("organUuid") String organUuid) {
        logger.info("organUuid" + organUuid);
        List<ZtreeEntity> list=organService.getOrganZtreeListByOrganId(organUuid);
        return list;
    }

    @RequestMapping("/addOrgan")
    @ResponseBody
    public String addOrgan(String organBianMa, String organName, String organType, String organBeiZhu) {
        logger.info("organBianMa" + organBianMa);
        logger.info("organName" + organName);
        logger.info("organType" + organType);
        logger.info("organBeiZhu" + organBeiZhu);
        organService.addOrgan(organBianMa,organName,organType,organBeiZhu);
        return getSuccessMessage("organ.add.success");
    }

    @RequestMapping("/delOrgan")
    @ResponseBody
    public String delOrgan(String organBianMa){
        logger.info("organBianMa" + organBianMa);
        organService.delOrgan(organBianMa);
        return getSuccessMessage("organ.del.success");
    }
}
